package top.lvkun.quartz.job;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import top.lvkun.basic.constant.Constant;
import top.lvkun.order.domain.AdoptOrder;
import top.lvkun.order.service.IAdoptOrderService;
import top.lvkun.pay.domain.PayBill;

import java.util.Map;

/**
 * 自动取消订单的Job
 *  其实就是去修改订单表和支付单的数据状态为 已取消
 * @author Administrator
 * @version 1.0
 * @date 2021/1/24 14:25
 */
public class CancelOrderJob implements Job {

    @Autowired
    private IAdoptOrderService adoptOrderService;
//    @Autowired
//    private IProductOrderService productOrderService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("超时未完成支付：自动取消订单.........");
        //1.先获取参数
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        //先从JobDataMap中通过params为key获取到Map<String,Object>集合
        Map<String,Object> params = (Map<String, Object>) jobDataMap.get("params");
        //再从Map<String,Object>集合中获取订单对象和支付单对象
        AdoptOrder adoptOrder = (AdoptOrder) params.get("adoptOrder");
        PayBill payBill = (PayBill) params.get("payBill");

        //2.调用service层方法取消订单
        if(Constant.BUSINESS_TYPE_ADOPT.equals(payBill.getBusinessType())){
            //宠物领养订单
            adoptOrderService.cancelOrder(adoptOrder, payBill);
        }else if(Constant.BUSINESS_TYPE_PRODUCT.equals(payBill.getBusinessType())){
            //商品服务订单
        }
    }
}
